package com.gzhryc.shared_device.oem.code.agent.dao;

import java.sql.SQLException;
import java.util.List;

import com.gzhryc.jdbc.BaseDao;
import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.Query;
import com.gzhryc.shared_device.oem.code.agent.dao.db.AgentTypeRel;
import com.gzhryc.shared_device.oem.code.agent.dao.models.AgentTypeCount;

public class AgentTypeRelDao extends BaseDao<AgentTypeRel> {

    public AgentTypeRelDao(String jdbcKey){
        super(jdbcKey);
    }
    
    public List<AgentTypeCount> countGroupTypeId(Conditions conditions) throws SQLException {
    	String sql = "SELECT type_id AS typeId,count(1) AS useCount FROM " + this.tableName;
    	Query query = new Query(sql);
    	query.appendSql(conditions.toSql(query.getParams(), true));
    	query.appendSql(" GROUP BY type_id");
    	return this.jdbcHelper.find(query, AgentTypeCount.class);
    }
    
    public List<Long> findTypeIds(Conditions conditions) throws SQLException{
    	Query query = new Query("SELECT type_id FROM " + this.tableName);
    	query.appendSql(conditions.toSql(query.getParams(), true));
    	return this.jdbcHelper.findFirstField(query, Long.class);
    }
}
